package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;


public class 发货前退款测试 {
	private static final String url = "http://192.168.50.130:8888/wms-sf/oms";
	
	public static void main(String[] args) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
			String data = "eydwcHJvZHVjdF9zbic6JzIzMzQxJywnYXBwbHlfdHlwZSc6JzAnLCdvcmRlcl9zbic6JzE1MTc5MDcwOTM2ODMwMDMwNSd9";
			String sign = "5f5c55e72763e2145570f83d6a6dd4ab";
			StringBuffer sb = new StringBuffer();
			sb.append("{\r\n");
			sb.append("\"method\":\"aftersale.checkOrderStatus\",\r\n");
			sb.append("\"timestamp\":\"" + sdf.format(new Date()) + "\",\r\n");
			sb.append("\"app_key\":\"test_3006\",\r\n");
			sb.append("\"sign\":\"" + sign + "\",\r\n");
			sb.append("\"data\":\"" + data + "\"\r\n}");
			String requestResult = doPost(sb.toString(), url, "application/json");
			System.out.println("requestResult============="+requestResult);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}

}
